package cn.iocoder.yudao.module.lfd.service.appointmentitem;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.lfd.controller.admin.appointmentitem.vo.AppointmentItemCreateReqVO;
import cn.iocoder.yudao.module.lfd.controller.admin.appointmentitem.vo.AppointmentItemExportReqVO;
import cn.iocoder.yudao.module.lfd.controller.admin.appointmentitem.vo.AppointmentItemPageReqVO;
import cn.iocoder.yudao.module.lfd.controller.admin.appointmentitem.vo.AppointmentItemUpdateReqVO;
import cn.iocoder.yudao.module.lfd.convert.appointmentitem.AppointmentItemConvert;
import cn.iocoder.yudao.module.lfd.dal.dataobject.appointmentitem.AppointmentItemDO;
import cn.iocoder.yudao.module.lfd.dal.mysql.appointmentitem.AppointmentItemMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * 预约项目 Service 实现类
 *
 * @author 陈星星
 */
@Service
@Validated
public class AppointmentItemService {

    @Resource
    private AppointmentItemMapper appointmentItemMapper;

    
    public Long createAppointmentItem(AppointmentItemCreateReqVO createReqVO) {
        // 插入
        AppointmentItemDO appointmentItem = AppointmentItemConvert.INSTANCE.convert(createReqVO);
        appointmentItemMapper.insert(appointmentItem);
        // 返回
        return appointmentItem.getId();
    }

    
    public void updateAppointmentItem(AppointmentItemUpdateReqVO updateReqVO) {
        // 校验存在
        validateAppointmentItemExists(updateReqVO.getId());
        // 更新
        AppointmentItemDO updateObj = AppointmentItemConvert.INSTANCE.convert(updateReqVO);
        appointmentItemMapper.updateById(updateObj);
    }

    
    public void deleteAppointmentItem(Long id) {
        // 校验存在
        validateAppointmentItemExists(id);
        // 删除
        appointmentItemMapper.deleteById(id);
    }

    private void validateAppointmentItemExists(Long id) {
        if (appointmentItemMapper.selectById(id) == null) {
//            throw exception(APPOINTMENT_ITEM_NOT_EXISTS);
        }
    }

    
    public AppointmentItemDO getAppointmentItem(Long id) {
        return appointmentItemMapper.selectById(id);
    }

    
    public List<AppointmentItemDO> getAppointmentItemList(Collection<Long> ids) {
        return appointmentItemMapper.selectBatchIds(ids);
    }

    
    public PageResult<AppointmentItemDO> getAppointmentItemPage(AppointmentItemPageReqVO pageReqVO) {
        return appointmentItemMapper.selectPage(pageReqVO);
    }

    
    public List<AppointmentItemDO> getAppointmentItemList(AppointmentItemExportReqVO exportReqVO) {
        return appointmentItemMapper.selectList(exportReqVO);
    }

    public List<AppointmentItemDO> getAppointmentItemList(Long appointmentId) {
       return appointmentItemMapper.selectList("appointment_id",appointmentId);
    }
}
